﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Silvia.Models.Admin
{
    public class BaseModel
    {
        public List<Menu> MenuList { get; set; }
        public string Caption { get; set; }

        public Menu SelectMenu { get; set; }

        public BaseModel()
        {
            MenuList = new List<Menu>() 
            {
                new Menu(){ Title = "页面管理" , Key = "" , SubMenu = new List<Menu>()
                {
                    new Menu(){ Title = "首页图片" , Key = "/Admin/HomePhoto"},
                    new Menu(){ Title = "联系我们" , Key = "/Admin/Contact"},
                    new Menu(){ Title = "报价" , Key = "/Admin/PriceBook"},
                    new Menu(){ Title = "团队管理" , Key = "/Admin/TeamMgt"},
                    new Menu(){ Title = "其他设置" , Key = "/Admin/OtherSetting"},
                }},
                new Menu(){ Title = "相册管理" , Key = "", SubMenu = new List<Menu>()
                {
                    new Menu(){ Title = "相册类别" , Key = "/Admin/AlbumMgt"},
                    new Menu(){ Title = "相册子类别" , Key = "/Admin/SubAlbumMgt"},
                    new Menu(){ Title = "相册" , Key = "/Admin/PhotoMgt"},
                }},
             };
        }

        public void Select(string title)
        {
            foreach (var menu in MenuList)
            {
                menu.IsSelect = false;
                if (menu.Title == title)
                {
                    menu.IsSelect = true;
                    foreach (var subMenu in menu.SubMenu)
                    {
                        subMenu.IsSelect = false;
                    }
                }
                else
                {
                    foreach (var subMenu in menu.SubMenu)
                    {
                        subMenu.IsSelect = false;
                        if (subMenu.Title == title)
                        {
                            subMenu.IsSelect = true;
                            SelectMenu = subMenu;
                            menu.IsSelect = true;
                        }
                    }
                }
            }
        }
    }
}